
$(function() {

    Global.userid = getUrlParameter("user-id");

    Global.type = getUrlParameter("type");

    Global.code = getUrlParameter("code");

    Global.language = getUrlParameter("request-locale");
    
    Global.isMdp = getUrlParameter("isMdp");//判断Portal域
    if (Global.type && Global.code && Global.userid && Global.language){

         if (Global.type != "Pipeline"){
        	 var liset = dojo.query(".liset")[0];
             dojo.style(liset,"display","none");
             var alocation = dojo.query(".alocation")[0];
             alocation.innerHTML = "Store Info";
         }
         getHeadTitle();
         getDic(initTabWidget);
         initTabEvt();

    }else{
        alert("请登录!");
        location.href="about:blank";
    }
});

function getHeadTitle(){
	$.ajax({
		type:'get',
		url:"./services/detailinfoservice/headtitle",
		data:{
			code:Global.code,
			type:Global.type
		},
		dataType:'json',
		success:function(response){
			if (response.info){
				var title = response.info["Code"];
				title += response.info["SiteName"]?"_" + response.info["SiteName"]:"";
				title += response.info["Process_EnName"]?"_" + response.info["Process_EnName"]:"";
				title += response.info["StoreType_EnName"]?"_" + response.info["StoreType_EnName"]:"";
				title += response.info["StoreStatus_EnName"]?"_" + response.info["StoreStatus_EnName"]:"";
				var aheadtitle = dojo.query(".headtitle")[0];
				aheadtitle.innerHTML = title;
			}
		},
		error:function(response){
			console.log("获取Title出错");
		}
	});
}



function initTabWidget(){
    var loctionTab = dojo.query(".body_location")[0];
    require(["widgets/detailInfoWidget/locationInfoWidget/LocationInfoWidget"],function(LocationInfoWidget){
        Global.locationInfoWidget = new LocationInfoWidget({Code:Global.code,Type:Global.type});//{Code:Global.code,Type:Global.type}
        Global.locationInfoWidget.startup();
        Global.locationInfoWidget.placeAt(loctionTab);
        Global.locationInfoWidget.regRadioChange();
    });    
    
    if (Global.type == "Pipeline"){

            var setTab = dojo.query(".body_sales")[0];

            require(["widgets/detailInfoWidget/setInfoWidget/SetInfoWidget"],function(SetInfoWidget){

                Global.setInfoWidget = new SetInfoWidget({PPCode:Global.code});

                Global.setInfoWidget.startup();

                Global.setInfoWidget.placeAt(setTab);

            });
    }

    var attachmentTab = dojo.query(".body_attachment")[0];

    require(["widgets/detailInfoWidget/attachmentInfoWidget/AttachmentInfoWidget"],function(AttachmentInfoWidget){

        Global.attachmentInfoWidget = new AttachmentInfoWidget({Code:Global.code,Type:Global.type});

        Global.attachmentInfoWidget.startup();

        Global.attachmentInfoWidget.placeAt(attachmentTab);

    });

    

    var trafficTab = dojo.query(".body_traffice")[0];

    require(["widgets/detailInfoWidget/trafficCountInfoWidget/TrafficCountInfoWidget"],function(TrafficCountInfoWidget){

        Global.trafficCountInfoWidget = new TrafficCountInfoWidget({Code:Global.code,Type:Global.type});

        Global.trafficCountInfoWidget.startup();

        Global.trafficCountInfoWidget.placeAt(trafficTab);

    });
    slideCtrl();
    
}



function initTabEvt() {
    $('.pmt-content-tabs > li').bind('click',getSelectPPItem);
}

// 点击Tab切换

function getSelectPPItem(evt){
    var curTarget = evt.target; 
    if($(curTarget).hasClass("active")) return;
    
    $(curTarget).siblings().removeClass("active");
    $(curTarget).addClass("active");
    
    $(".tab-content > div").removeClass("active");
    $(curTarget.getAttribute("data-bind")).addClass("active");  
} 


